#!/usr/bin/env python3
# coding:utf-8
import subprocess
 
if __name__ == '__main__':
    cmd = 'ping www.baidu.com -c 3'
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    while p.poll() is None:
        line = p.stdout.readline()
        line = line.decode('utf-8').strip()
        if line:
            print('Subprogram output: {}'.format(line))
    if p.returncode == 0:
        print('Subprogram success')
    else:
        print('Subprogram failed')